﻿/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;

namespace DaveSexton.DocProject
{
	[Serializable]
	public struct Keyword : IEquatable<Keyword>
	{
		#region Public Properties
		public static readonly Keyword Empty = new Keyword();

		public string Index
		{
			get
			{
				return index;
			}
		}

		public string Term
		{
			get
			{
				return term;
			}
		}
		#endregion

		#region Private / Protected
		private readonly string index, term;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="Keyword" /> structure.
		/// </summary>
		public Keyword(string index, string term)
		{
			this.index = index;
			this.term = term;
		}
		#endregion

		#region Methods
		public override bool Equals(object obj)
		{
			return obj is Keyword && Equals((Keyword) obj);
		}

		public bool Equals(Keyword other)
		{
			return string.Equals(index ?? "", other.index ?? "", StringComparison.OrdinalIgnoreCase)
				&& string.Equals(term ?? "", other.term ?? "", StringComparison.OrdinalIgnoreCase);
		}

		public override int GetHashCode()
		{
			return (index ?? "").GetHashCode() ^ (term ?? "").GetHashCode();
		}

		public override string ToString()
		{
			return "{" + index + ", " + term + "}";
		}
		#endregion

		#region Operator Overloads
		public static bool operator ==(Keyword keyword1, Keyword keyword2)
		{
			return keyword1.Equals(keyword2);
		}

		public static bool operator !=(Keyword keyword1, Keyword keyword2)
		{
			return !keyword1.Equals(keyword2);
		}
		#endregion
	}
}
